<template>
	<view class="content">
		<view class="all">
			<view class="every" v-for="item in list">
				<view class="every_img" :style="{backgroundImage:`url(${item.img})`}">
					<view class="every_ji" v-if="item.id%2==1">
						<view @click="go(item.id,item.see)">{{item.name}}</view>
						<view>{{item.title}}</view>
						<view>{{item.txt}}</view>
						<view style="width: 100px;height: 30px;display: flex;align-items: center;">
							<u-icon name="heart-fill" @click="nolike(item.like,item.id)" v-if="gg(item.id)" color="red"></u-icon>
							<u-icon name="heart" @click="like(item.like,item.id)" v-else></u-icon>
							{{item.like}}
							<u-icon name="eye"></u-icon>
							{{item.see}}
						</view>
					</view>
					<view class="every_ou" v-else>
						<view @click="go(item.id)">{{item.name}}</view>
						<view>{{item.title}}</view>
						<view>{{item.txt}}</view>
						<view style="width: 100px;height: 30px;display: flex;align-items: center;">
							<u-icon name="heart-fill" @click="nolike(item.like,item.id)" v-if="gg(item.id)" color="red"></u-icon>
							<u-icon name="heart" @click="like(item.like,item.id)" v-else></u-icon>
							{{item.like}}
							<u-icon name="eye"></u-icon>
							{{item.see}}
						</view>
					</view>
					
				</view>
			</view>
			<view style="width: 100%;height: 50px;"></view>
			
			
		</view>
	</view>
</template>

<script>
	import {getzwyZL,putzwyZLedit} from '../../../utils/api.js'
	export default {
		data() {
			return {
				list:[],
				likes:[],
				lk:''
			}
		},
		onLoad() {
			this.kai()
		},
		methods: {
			kai(){
				getzwyZL().then(res=>{
					this.list=res.data
					console.log(res);
				})
			},
			go(e,v){
				console.log(e);
				putzwyZLedit({see:Number(v)+1,id:e}).then(res=>console.log(res))
				setTimeout(()=>{this.kai()},100)
				uni.navigateTo({
					url: '/pages/tabbar/tabbar-4/tabbar-4-detail/tabbar-4-detail?id=' + e
				})
			},
			like(v,e){
				console.log(v,e);
				this.likes.push(e)
				putzwyZLedit({like:Number(v)+1,id:e}).then(res=>console.log(res))
				setTimeout(()=>{this.kai()},100)
			},
			nolike(v,e){
				console.log(v,e);
				this.likes=this.likes.filter(item=>item!=e)
				putzwyZLedit({like:Number(v)-1,id:e}).then(res=>console.log(res))
				setTimeout(()=>{this.kai()},100)
			},
			 gg(id){
				return this.likes.some( item => item == id )
			}
			
		}
	}
</script>

<style>
	.all{
		width: 100%;
		height: calc(100vh - 94px);
	}
	.all .every{
		width: 100%;
		height: 33.33%;
		padding: 20px;
		box-sizing: border-box;
	}
	.all .every_img{
		width: 100%;
		height: 100%;
		padding: 20px;
		box-sizing: border-box;
		border-radius: 20px;
		position: relative;
	}
	.every_ji{
	 	position: absolute;
	 	left: 10%;
	}
	.every_ou{
		position: absolute;
		right: 10%;
	}
</style>
